#include "stdafx.h"

#define SINANGLE_C

#include <math.h>

#ifdef __USING_JAR__
#include "..\..\Common\Config.h"
#else
#include "structs.h"
#include "sincos.h"
#include "sinangle.h"
#include "MathPI.h"
#endif

void TSinAngle::Init( TSinParams *params, int iGz0)
 {
 if (params!=NULL)
  p= *params;
 if (iGz0)
  iGz= iGz0;
 dt= double(1.0)/iGz;
 iCounter= 0;
 }

void TSinAngle::Get( double &dValue, double &dVelocity)
 {
/*
 double dSin= sin(PI2*(iCounter*dt)/p.iPeriod);
 double dRet= p.iValue + dSin*p.iAmpl;
*/
 if (p.dPeriod<0.0001)
  {
  dValue= 0;
  dVelocity= 0;
  return;
  }
 double x= pi2*(iCounter*dt)/p.dPeriod;
  // Value= const + Ampl*sin( 2*pi*t/T)
 dValue= p.dValue + my_sin(x)*p.dAmpl;
  // Velocity = Value' = Ampl*2*pi/T * cos(2*pi*t/T)
 dVelocity= my_cos(x)*p.dAmpl *pi2/p.dPeriod;

 if ( ++iCounter==(p.dPeriod*iGz) )
  iCounter= 0;
 }
